<template>
	<view class="main">
		<view class="list" v-for="(item,index) in list" :key="index">
			<view class="list-head flex align between">
				<view>（任务id）{{item.rank_id}}</view>
				<view>{{item.addtime}}</view>
			</view>
			<view class="list-info flex align between">
				<view class="list-info-left">
					<view class="flex align">
						<view>任务名</view>
						<text>{{item.rank.title}}</text>
					</view>
					<view class="flex align">
						<view>主页链接</view>
						<text>{{item.rank.url}}</text>
					</view>
					<view class="flex align">
						<view>长尾词</view>
						<text>{{item.rank.keywords}}</text>
					</view>
					<view class="flex align">
						<view>排名</view>
						<text>{{item.rank_num==0?'--':item.rank_num}}</text>
					</view>
				</view>
				<view class="list-info-right">
					<view>当前状态</view>
					<view :style="item.rank.status==1?'background:#00ACFF':item.rank.status==2?'background:#369805':'background:#B40A05'">{{item.rank.status==1?'查询中':item.rank.status==2?'已完成':'已暂停'}}</view>
				</view>
			</view>
		</view>
		<xw-empty :isShow="empty" text="暂无数据" textColor="#777777"></xw-empty>
		<uni-load-more :status="status" v-if="!empty" :content-text="loadText"></uni-load-more>
	</view>
</template>

<script>
	import {
		storeadminTaskIndex,
		rankDel
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				searchValue: '',
				keyword: '',
				show: false,
				totalPage: 1,
				page: 0,
				offset: 20,
				list: [],
				scrollTop: 0,
				empty: false,
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				status: 'loadmore',
				merge_keyword: '',
				statusA:'',
				rank_id:''
			};
		},
		onShow() {
			
		},
		onLoad(option) {
		  this.rank_id = option.id	
		  this.getlist();
		},
		onPageScroll(e) {
			const that = this;
			that.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			const that = this;
			that.getlist();
		},
		methods: {
			toStatus(s){
				this.statusA = s
				this.page = 0
				this.list = []
				this.getlist();
			},
			// 删除
			toDel(id) {
				let that = this
				uni.showModal({
					title: "提示",
					content: "消耗金额不退回，确认是否删除任务？",
					showCancel: true,
					success: res => {
						if (res.confirm) {
							that.delCom(id)
						} else {

						}
					}

				})
			},
			async delCom(id) {
				let obj = {
					ids: id
				}
				const result = await rankDel(obj)
				if (result.code == 1) {
					uni.showToast({
						title: '删除成功'
					})
					this.show = false
					this.page = 0
					this.list = []
					this.getlist()
				} else {
					uni.showToast({
						title: result.msg,
						icon: 'none'
					})
				}
			},
			input() {
				this.page = 0
				this.list = []
				this.getlist()
			},
			async getlist() {
				const that = this;
				const {
					totalPage,
					page,
					offset,
					list,
					group_id,
					type,
					merge_keyword,
					statusA,
					rank_id
				} = that;

				let obj = {
					menu_url: 'rank_task',
					limit: offset,
					offset: page,
					sort: 'id',
					order: 'desc',
					rank_id:rank_id,
					_: new Date().getTime()
					// filter:merge_keyword=='',
					// op:encodeURIComponent(JSON.stringify(filter))
				};
				if(statusA==''&&merge_keyword==''){
					obj.filter ={}
					obj.op ={}
				}else{
					if (merge_keyword != '') {
						if(statusA==''){
							obj.filter = JSON.stringify({
								"title": merge_keyword.toString()
							})
							obj.op = JSON.stringify({
								"title": '='
							})
						}else{
							obj.filter = JSON.stringify({
								"title": merge_keyword.toString(),"status":statusA
							})
							obj.op = JSON.stringify({
								"title": '=',"status":'='
							})
						}
						
					}else{
						obj.filter = JSON.stringify({
							"status":statusA
						})
						obj.op = JSON.stringify({
							"status":'='
						})
					}
				}
				
				that.status = 'loading';
				if (totalPage > page) {
					let result = await storeadminTaskIndex(obj);
					that.page = page + 1;
					if (result.total == 0) {
						that.empty = true;
						that.status = 'nomore';
						return;
					}
					that.empty = false;
					setTimeout(() => {
						that.status = 'loadmore';
					}, 500);
					that.list = list.concat(result.rows);
					that.totalPage = Math.ceil(result.total / offset);
				} else {
					setTimeout(() => {
						that.status = 'nomore';
					}, 500);
				}
			},
			toShow() {
				this.show = !this.show
			},
			toUrl() {
				uni.navigateTo({
					url: '/pages/rank/searckAdd'
				})
			},
			toUrl2(id){
				uni.navigateTo({
					url: '/pages/rank/look?id='+id
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		margin: 13rpx 30rpx;

		.topSearch {
			.addBtn {
				background: #FFCDB8;
				color: white;
				border-radius: 14rpx;
				font-size: 20rpx;
				padding: 8rpx 14rpx;
			}
		}

		.tabs {
			background: white;
			padding: 15rpx 0;

			.tab-item {
				flex: 1;
				text-align: center;
				justify-content: center;
				position: relative;

				image {
					width: 22rpx;
					height: 12rpx;
					margin-left: 26rpx;
				}

				.tab-option {
					position: absolute;
					width: 100%;
					top: 60rpx;
					background: white;
					box-shadow: 1rpx 1rpx 1rpx 2rpx gainsboro;

					view {
						padding: 16rpx 0;
						border-bottom: solid 1rpx #D9D9D9;
					}
				}
			}
		}

		.list {
			background: white;
			margin-top: 19rpx;
			border-radius: 15rpx;

			.list-head {
				margin: 18rpx;
				padding: 26rpx 0 8rpx 0;
				border-bottom: solid 1rpx #D6D6D6;
				padding-bottom: 8rpx;

				view:nth-child(1) {
					font-size: 28rpx;
					font-weight: bold;
				}

				view:nth-child(2) {
					color: #868686;
					font-size: 18rpx;
				}
			}

			.list-info {
				padding: 8rpx 0;
				padding: 0 41rpx 23rpx;

				.list-info-left {
					view {
						margin-bottom: 10rpx;
					}

					.flex {
						view {
							width: 100rpx;
						}
					}

					font-size: 24rpx;

					text {
						margin-left: 77rpx;
						font-weight: bold;
					}
				}

				.list-info-right {
					text-align: center;

					view:nth-child(1) {
						color: #868686;
						font-size: 18rpx;
					}

					view:nth-child(2) {
						background: #AFAFAF;
						color: white;
						font-size: 28rpx;
						padding: 0 17rpx;
						border-radius: 20rpx;
						margin-top: 16rpx;
					}
					view:nth-child(3) {
						background: #f39c12;
						color: white;
						font-size: 28rpx;
						padding: 0 17rpx;
						border-radius: 20rpx;
						margin-top: 16rpx;
					}
				}
			}

			.trash {
				justify-content: center;
				background: #2D2D2D;
				color: white;
				font-size: 32rpx;
				font-weight: bold;
				padding: 15rpx 0;
				border-radius: 0 0 15rpx 15rpx;
			}
		}
	}
</style>